// 定时任务
// 每天 00:00:00 触发
const schedule = require('node-schedule');
const init = require("./init.js")

const timedExecution =  async () =>{
    const StudentSInfon = await init.StudentSInfon.findAll({
        attributes:["id"],
        where:{
            BednumberId:{
                [init.Op.not]: null
            }
        }
    })
   const getUp = JSON.parse(JSON.stringify(StudentSInfon)).map(item => {
    return {
        time: +init.moment.utc(),
        isGetup: -1,
        StudentSInfonId: item.id
    }
   })
   const endResult = JSON.parse(JSON.stringify(StudentSInfon)).map(item => {
    return {
        time: +init.moment.utc(),
        isDestination: -1,
        StudentSInfonId: item.id
    }
   })
   init.Getup.bulkCreate(getUp).then(data => {
    console.log("起床完成");
   })
   init.Destination.bulkCreate(endResult).then(data => {
    console.log("归宿完成");
   })
   
}



function scheduleCronStyle(){
    schedule.scheduleJob("0 0 0 * * *",function(){
        console.log("执行");
        timedExecution()
    })
}
scheduleCronStyle()